package cn.szq.concurrent.thread.create;

import java.util.Random;
import java.util.concurrent.*;

/**
 * @ClassName: CallableTask
 * @Description:
 * @Author: szq
 * @Date: 2021-09-26 15:17:08
 */
public class CallableTask  implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        return new Random().nextInt();
    }

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(10);
        //提交任务，并用Future提交返回结果
        Future<Integer> future = executorService.submit(new CallableTask());
        System.out.println(future.get());
    }
}
